using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;

namespace SecurityAccessLayer
{
    public static class SAL
    {
        public static int _numberOfCurrentUsers = 0;

        //Public layer
        #region Public Methods
        /// <summary>
        /// Method test
        /// </summary>
        /// <returns></returns>
        public static string MyToString() // Can't override by inherited memeber is hidden? hmm
        {
            return "SAL NEW";
        }
        
        /// <summary>
        /// Check is user is logged on and if not, validate then log them in.
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static object LogonAsUser(int userID)
        {
            //TODO:  Validate if user is logged on or not.
            //object o = FetchPermissionsByUser(userID);
            return 1;
        
        }

        /// <summary>
        /// Attempts to log user off of the system when called.
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static bool LogoffUser(string userName)
        {
            //LogonState.NotLoggedIn = true;
            return true;  

        }

        /// <summary>
        /// Tests to see if the user has been validated
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static ValidState IsValidatedUser(string userName, out int userID)
        {
            userID = -1;
            ValidState validState = dalIsValidatedUser(userName);

            if(validState == ValidState.Valid)
            {
                userID = DAL.GetUserId(userName);
            
            }
            return validState;
            
        }

        public static ValidState IsValidatedUser(int userID)
        {
            return dalIsValidatedUser(userID);
        }

        public static bool CanUserDoStuff(int userID, DoStuffType doStuff)
        {
            return dalCanDoStuff(userID, doStuff);
        }

        #endregion

        //Private layer
        #region - Private Methods
        /// <summary>
        /// Retrieves permission granted by userID
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        private static object FetchPermissionsByUser(string userName)
        {
            object o = null;

            //if (DAL.IsUserValid(userName) == LogonState.LoggedIn)
            //{
            //    o = DAL.GetPermissionsByUserName("");

            //}
            //else
            //{

            //}
            return o;
        }

        private static ValidState dalIsValidatedUser(string userName)
        {
            ValidState status = DAL.IsUserValid(userName);
            if (status == ValidState.Valid)
            {
                DAL.GetUserId(userName);
            }
            return status;
        }

        private static ValidState dalIsValidatedUser(int userID)
        {
            return DAL.IsUserValid(userID);
        }

        private static bool dalCanDoStuff(int userID, DoStuffType doStuf)
        {
            return DAL.CanUserDoStuff(userID, doStuf);
        }
        #endregion

    }
}
